import 'package:flutter/material.dart';
import 'package:startapp/pages/Home.dart';
import 'package:startapp/pages/Login.dart';

class MyRouter {
  final Map<String, Function> _routes = {
    "/": (context) => HomePage(),
    "/login": (context) => LoginPage(),
  };

  Route<dynamic> routers(RouteSettings settings) {
    final String? name;
    if (2 == 1) {
      name = "/login";
    } else {
      name = settings.name;
    }

    Function? pageContentBuilder = this._routes[name];

    if (pageContentBuilder != null) {
      if (settings.arguments != null) {
        final Route route = MaterialPageRoute(
            builder: (context) =>
                pageContentBuilder!(context, arguments: settings.arguments));
        return route;
      } else {
        final Route route = MaterialPageRoute(
            builder: (context) => pageContentBuilder!(context));
        return route;
      }
    } else {
      pageContentBuilder = this._routes['/login'];
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder!(context));
      return route;
    }
  }
}
